﻿Public Class TipoHorasExtra 
    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            PanelArriba.Enabled = True
            PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            Modificar.Enabled = True
            Eliminar.Enabled = True
            imprimir.Enabled = True
            PanelArriba.Enabled = False
            PanelAbajo.Enabled = True

        End If
    End Sub
    Private Sub HorastipoBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles HorastipoBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.HorastipoBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub TipoHorasExtra_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.horastipo' table. You can move, or remove it, as needed.
        Me.HorastipoTableAdapter.Fill(Me.DbFireAndIceDataSet.horastipo)

    End Sub

    Private Sub agregar_Click(sender As System.Object, e As System.EventArgs) Handles agregar.Click
        BindingNavigatorAddNewItem.PerformClick()
        Mostrar()
    End Sub

    Private Sub modificar_Click(sender As System.Object, e As System.EventArgs) Handles modificar.Click
        Mostrar()
    End Sub

    Private Sub eliminar_Click(sender As System.Object, e As System.EventArgs) Handles eliminar.Click

    End Sub

    Private Sub guardar_Click(sender As System.Object, e As System.EventArgs) Handles guardar.Click
        If DescripcionTextBox.Text.Length = 0 Then
            ErrorProvider1.SetError(DescripcionTextBox, "Debe ingresar una Descripción")
            Return
        End If
        ErrorProvider1.SetError(DescripcionTextBox, Nothing)

        If ValorTextEdit.EditValue = 0 Then
            ErrorProvider1.SetError(DescripcionTextBox, "Debe ingresar una Porcentaje")
            Return
        End If
        ErrorProvider1.SetError(ValorTextEdit, Nothing)

        Try
            HorastipoBindingNavigatorSaveItem.PerformClick()
            AlertControl1.AppearanceCaption.ForeColor = Color.Green
            AlertControl1.Show(Me, "Advertencia", "Se guardó el resgistro satisfactoriamente")
            Mostrar()

        Catch ex As Exception
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Error", "No se pudo guardar el registro")
        End Try
    End Sub

    Private Sub ValorTextEdit_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles ValorTextEdit.KeyPress
        If Char.IsLetter(e.KeyChar) Then
            e.Handled = True
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Advertencia", "Solo puede ingresar números")
            ValorTextEdit.Focus()
        End If
    End Sub

    Private Sub cancelar_Click(sender As System.Object, e As System.EventArgs) Handles cancelar.Click
        ErrorProvider1.SetError(DescripcionTextBox, Nothing)
        ErrorProvider1.SetError(ValorTextEdit, Nothing)
        Mostrar()
        Try
            Me.HorastipoTableAdapter.Fill(Me.DbFireAndIceDataSet.horastipo)
        Catch ex As Exception
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Error", "No puede cancelar")
        End Try

    End Sub
End Class